﻿using B.S.Base.Read.API.Dto;
using MediatR;
using Microsoft.EntityFrameworkCore;
using WEBAPI.API.Application.Command;
using WEBAPI.Damoin;
using WEBAPI.ErroeCode;
using WEBAPI.Indaseture.Infasetures;

namespace B.S.Base.Read.API.Application.CommandHandLer
{
    public class GetMeunRoleCommandHandLer : IRequestHandler<GetMenuRoleCommand, APIResult<List<RoleModel>>>
    {

        IBaseRepostiy<RoleModel> _roleModel;

        public GetMeunRoleCommandHandLer( IBaseRepostiy<RoleModel> roleModel)
        {
  
            _roleModel = roleModel;
        }

        public async Task<APIResult<List<RoleModel>>> Handle(GetMenuRoleCommand request, CancellationToken cancellationToken)
        {
            var list =_roleModel.GetAll().Where(x=>!x.IsDeleted);
            
            return new APIResult<List<RoleModel>>
            {
                Code = ResultCode.Ok,
                Data = list.ToList(),
                Message = "获取成功"
            };
        }
    }
}
